<div class="container-fluid" style="margin-top: 10px;">
    <div class="row">
        <form id="inputForm" action="edit">
            {:buildForm($config,$data)}
            <div class="col-sm-12" style="margin-top: 10px;margin-bottom: 20px;text-align: center">
                {if $data['IS_FIXED'] == 0}
                <button id="addButton" type="button" class="btn btn-info btn-sm">保存</button>
                {/if}
                <button type="reset" class="btn btn-default btn-sm">重置</button>
                <button id="printButton" type="button" class="btn btn-success btn-sm">打印</button>
                {if $data['IS_FIXED'] == 0}
                <button id="toFix" type="button" class="btn btn-success btn-sm">转固</button>
                {/if}
            </div>
        </form>
    </div>
</div>

<script>

    $(function () {
        $("#addButton").on('click',function () {
            layer.confirm('确认更新信息吗？',function (index) {
                layer.close(index);
                layer.load();
                $("#inputForm").ajaxSubmit(function (text) {
                    console.log(text);
                    layer.closeAll('loading');
                    var json = JSON.parse(text);
                    if(json['code'] == '200'){
                        layer.alert(json['msg'],{icon:1},function (index) {
                            layer.close(index);
                            parent.location.reload();
                        })
                    }
                    else{
                        layer.alert(json['msg'],{icon:2});
                    }
                });
            });
        });
        $("#printButton").on('click',function () {
            var id = $("input[name='BUILDING_NO']").val();
            window.open("{:url('printPage')}?id="+id);
        });

        $("#toFix").on('click',function () {
            layer.confirm('确认转固吗？',function (index) {
                layer.close(index);
                layer.load();
                var id = $("[name='BUILDING_NO']").val();
                $.ajax({
                    url:"{:url('toFix')}",
                    data:{id:id},
                    success:function (res) {
                        layer.closeAll('loading');
                        var json = JSON.parse(res);
                        if(json['code'] == '200'){
                            layer.alert(json['msg'],{icon:1},function (index) {
                                layer.close(index);
                                parent.location.reload();
                            });
                        }
                        else{
                            layer.alert(json['msg'],{icon:2});
                        }
                    },
                    error:function (res) {
                        layer.closeAll('loading');
                        layer.alert('网络错误',{icon:2});
                    }
                });
            });
        });
    });

</script>